'''
https://www.cnblogs.com/kaituorensheng/p/4445418.html

multiprocessing模块就是跨平台版本的多进程模块。


'''

import multiprocessing
import time
import os

def worker_1(sleep, arg1=0):
    print ("worker_1")

    for i in range(arg1):
        print(1, i)
        time.sleep(sleep)

    print ("end worker_1")

def worker_2(sleep, arg1):
    print ("worker_2")

    for i in range(arg1):
        print(2, i)
        time.sleep(sleep)

    print ("end worker_2")

def worker_3(sleep):
    print ("worker_3")
    time.sleep(sleep)
    print ("end worker_3")

if __name__ == "__main__":
    p1 = multiprocessing.Process(target = worker_1, args = (1, 50))
    p2 = multiprocessing.Process(target = worker_2, args = (1, 50))
    p3 = multiprocessing.Process(target = worker_3, args = (1,))

    p1.start()
    p2.start()
    p3.start()

    print("The number of CPU is:" + str(multiprocessing.cpu_count()))
    print('Parent process: %s.' % os.getpid())
    
    for p in multiprocessing.active_children():
        print("child   p.name:" + p.name + "\tp.id:" + str(p.pid))
    print ("END!!!!!!!!!!!!!!!!!")